import { http } from "@/utils";
import { createSlice } from '@reduxjs/toolkit'

const loginStore = createSlice({
    name:'login',
    initialState:{
        token:''
    },
    reducers:{
        setToken(state,action){
            state.token = action.payload
        }
    }
})

//创建异步
const {setToken} = loginStore.actions

const loginSetToken = (mobile,code)=>{
    console.log(mobile,'mobile')
    return async ()=>{
        const res = await http.post('http://geek.itheima.net/v1_0/authorizations',{
            mobile,
            code
        })
        setToken(res.data.token)
        // dispatch(setToken(res.data.token))
    }
}

export {loginSetToken}
const LoginReducer = loginStore.reducer
export default LoginReducer